<?php

namespace app\web\controller;
use app\web\model\LineAttributesModel;
use app\common\controller\StoreBaseController;
use think\Db;

/**
 * 自定义属性设置
 */
class LineAttributesController extends StoreBaseController
{
 	protected $model;
	
    protected function _initialize() {
        parent::_initialize();
        $this->model = new LineAttributesModel();
    }
    /**
     * 会员自定义属性
     * @author [longx] 
     */
    public function index(){
    	$store_id = session('storeInfo')['id'];
        $attrinfo = $this->model->where('store_id',$store_id)->find();
		if($attrinfo){
			if(request()->isAjax()){
	            $param = input('post.');  		       
	         	if ($this->model->allowField(true)->save($param,$param['id']) !== false) {
	                    $this->success('修改成功', url('line_attributes/index'));
	            } else {
	                $this->error('修改失败');
	            }
	        }
		}else{
			if(request()->isAjax()){
	        	$param=input('post.');
				//所属店铺id
				$param['store_id'] = session('storeInfo')['id'];
				if ($this->model->allowField(true)->save($param) !== false) {
	                    $this->success('添加成功', url('line_attributes/index'));
	            } else {
	                $this->error('添加失败');
	            }
        	}
		}   	
		$store_id = session('storeInfo')['id'];
        $this->assign('ad',$this->model->where('store_id',$store_id)->find());
        return $this->fetch();
    }
	
	 /**
     * 商品自定义属性
     * @author [longx] 
     */
    public function goodsattr(){
    	$store_id = session('storeInfo')['id'];
        $attrinfo = $this->model->where('store_id',$store_id)->find();
		if($attrinfo){
			if(request()->isAjax()){
	            $param = input('post.');  		       
	         	if ($this->model->allowField(true)->save($param,$param['id']) !== false) {
	                    $this->success('修改成功', url('line_attributes/goodsattr'));
	            } else {
	                $this->error('修改失败');
	            }
	        }
		}else{
			if(request()->isAjax()){
	        	$param=input('post.');
				//所属店铺id
				$param['store_id'] = session('storeInfo')['id'];
				if ($this->model->allowField(true)->save($param) !== false) {
	                    $this->success('添加成功', url('line_attributes/goodsattr'));
	            } else {
	                $this->error('添加失败');
	            }
        	}
		}   	
		$store_id = session('storeInfo')['id'];
        $this->assign('ad',$this->model->where('store_id',$store_id)->find());
        return $this->fetch();
    }
}